package com.qingzhuge.member.wx;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import com.qingzhuge.member.entity.SysThirdAppConfig;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public final class WxMaConfigurationUtil {
    private volatile static WxMaConfigurationUtil configurationUtil;
    public static WxMaConfigurationUtil build(){
        if (null == configurationUtil){
            synchronized (WxMaConfigurationUtil.class){
                if (null == configurationUtil) {
                    configurationUtil = new WxMaConfigurationUtil();
                }
            }
        }
        return configurationUtil;
    }

    public WxMaService getWxMaService(SysThirdAppConfig thirdAppConfig) {
        WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
        config.setAppid(thirdAppConfig.getAppId());
        config.setSecret(thirdAppConfig.getAppSecret());
        config.setToken(thirdAppConfig.getToken());
        config.setAesKey(thirdAppConfig.getEncodingAESKey());
        WxMaService service = new WxMaServiceImpl();
        service.setWxMaConfig(config);
        return service;
    }
}
